/*
ID:fuxiang2
PROG: gift1
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;




int main() {
	ofstream fout ("gift1.out");
	ifstream fin ("gift1.in");
	string str;
	int n;
	fin>>n;
	fin>>str;
	int maxn = 0;
	for(int i = 0 ; i < n ; i ++)
	{
		int l = (i-1 +n)%n;
		int r = (i+1 +n )%n;
		char col = 'b';
		bool flag = true;
		int num = 0;
		int re = 0;
		while(flag)
		{
			if(str[l]  != 'b')
			{
				if(col == 'b')
					col = str[i];
				else if(col != str[l])
					flag = false;

			}
			num ++ ;
			l  = (l-1 + n)%n;
		}
		re += num;
		flag = true ;
		num = 0;

		while(flag)
		{
			if(str[r]  != 'b')
			{
				if(col == 'b')
					col = str[i];
				else if(col != str[r])
					flag = false;

			}
			num ++ ;
			r  = (r-1 + n)%n;
		}
		re += num;
		
		if(maxn < re) maxn = re;

	}

	fout << maxn << endl;

	

	return 0;
}